package com.example.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author YAO
 * @create 2021-04-19 23:29
 */
public class Response1 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("曾到此一游 Response1");
        req.setAttribute("key1","value1");
        //设置重定向第一种方法：
        //设置响应状态码302，表示重定向
//        resp.setStatus(302);
        //设置响应头，说明新的地址在哪
//        resp.setHeader("Location","http://localhost:8089/07_servlet/response2");

        //设置重定向第二种方法（推荐）
        resp.sendRedirect("http://localhost:8089/07_servlet/response2");
    }
}
